<template>
  <div v-loading="loading" class="Refrigeration  h100">
    <div class="PageContent">
      <el-form ref="ruleForm" :inline="true" :model="ruleForm" class="PageItem margintop20" label-width="80px">
        <el-row :gutter="5" class="fileSearch">
          <el-form-item label="业务编码:">
            <el-input v-model="ruleForm.businessCode" clearable></el-input>
          </el-form-item>
          <el-form-item label="逝者姓名:">
            <el-input v-model="ruleForm.deadName" clearable></el-input>
          </el-form-item>
          <el-form-item label="冷藏日期:">
            <el-date-picker v-model="ruleForm.realityTimeStart" format="yyyy-MM-dd" placeholder="选择日期"
                            type="date"></el-date-picker>
            -
            <el-date-picker v-model="ruleForm.realityTimeEnd" format="yyyy-MM-dd" placeholder="选择日期"
                            type="date"></el-date-picker>
          </el-form-item>
          <el-form-item label="冷藏操作类型:" label-width="120px">
            <el-select
              v-model="ruleForm.processStateCode"
              placeholder="请选择"
            >
              <el-option label="全部" value></el-option>
              <el-option :value="2" label="已入藏"></el-option>
              <el-option :value="3" label="已出藏"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="冷柜类型:" label-width="120px">
            <el-select
              v-model="ruleForm.equipmentTypeCode"
              placeholder="请选择"
            >
              <el-option label="全部" value></el-option>
              <el-option :value="2" label="单间冷藏柜"></el-option>
              <el-option :value="3" label="普通冷藏柜"></el-option>
              <el-option :value="4" label="单体冷藏柜"></el-option>
              <el-option :value="5" label="守灵"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="柜号:">
            <el-input v-model="ruleForm.equipmentCode" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button v-if="btnRight.btnRefrigerationSearch" type="primary" @click="onSubmit('search')">查询</el-button>
            <el-button v-if="btnRight.btnRefrigerationExport" plain type="primary" @click="openExecl">导出Excel
            </el-button>
          </el-form-item>
        </el-row>
        <el-table
          :data="tableData"
          :header-cell-style="{background:'rgb(246,247,251)',color:'#606266'}"
          :height="tableHeight"
          border
          stripe>
          <el-table-column align='center' label="业务编码" prop="businessCode" sortable width="200">
          </el-table-column>
          <el-table-column
            align='center'
            label="逝者姓名"
            prop="deadName"
            width="100">
          </el-table-column>
          <el-table-column
            align='center'
            label="逝者性别"
            prop="deadGender"
            width="120">
          </el-table-column>
          <el-table-column
            align='center'
            label="年龄"
            prop="deadAge"
            width="100">
          </el-table-column>
          <el-table-column
            align='center'
            label="逝者证件号码"
            prop="certificateNo"
            width="200">
          </el-table-column>
          <el-table-column
            align='center'
            label="联系人"
            prop="contact"
            width="200">
          </el-table-column>
          <el-table-column
            align='center'
            label="联系方式"
            prop="contactPhone"
            width="200">
          </el-table-column>
          <el-table-column
            align='center'
            label="冷柜类型"
            prop="equipmentType"
            width="120">
          </el-table-column>
          <el-table-column
            align='center'
            label="冷柜号"
            prop="equipmentCode"
            width="120">
          </el-table-column>
          <el-table-column
            align='center'
            label="冷藏状态"
            prop="processState"
            width="150">
          </el-table-column>
          <el-table-column
            align='center'
            label="入藏时间"
            prop="realityInTime"
            width="200">
          </el-table-column>
          <el-table-column
            align='center'
            label="入藏操作人"
            prop="coldStorageInOperator"
            width="200">
          </el-table-column>
          <el-table-column
            align='center'
            label="出藏时间"
            prop="realityOutTime"
            width="200">
          </el-table-column>
          <el-table-column
            align='center'
            label="出藏操作人"
            prop="coldStorageOutOperator"
            width="200">
          </el-table-column>
        </el-table>
        <div style="text-align: center;
                      height: 0px;
                      line-height: 20px;
                      font-size: 18px;">
          显示{{
            pager.total === 0 ? 0 : (Math.ceil(pager.total / pager.pageSize) > 1 ? ((pager.currentPage - 1) * pager.pageSize + 1) : (1))
          }}到{{
            pager.total === 0 ? 0 : ((Math.ceil(pager.total / pager.pageSize) === pager.currentPage) ? (pager.total) : (pager.currentPage * pager.pageSize))
          }}条
        </div>
        <p style="text-align: right;margin-top: 20px;">
          <el-pagination
            :current-page="pager.currentPage"
            :page-size="pager.pageSize"
            :page-sizes="[10,20,30,50]"
            :total="pager.total"
            background
            layout="total,sizes,prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange">
          </el-pagination>
        </p>
      </el-form>
    </div>
  </div>
</template>

<script>
import {dataFormatetmd} from '@/utils/index'
import * as Type from '@/api/service'
import download from "@/api/download"

export default {
  name: "Refrigeration",
  data() {
    return {
      loading: false,
      type: [],
      ruleForm: {
        "businessCode": "",
        "deadName": "",
        "realityTimeStart": "",
        "processStateCode": "",
        "equipmentTypeCode": "",
        "equipmentCode": "",
        "pageSize": 0,
        "currentPage": 0,
        "exportExcelFlag": 0
      },
      pager: {
        "pageSize": 20,
        "total": 1,
        "currentPage": 1
      },
      tableData: [],
      tableHeight: 0,
      //按钮权限
      btnRight: {
        btnRefrigerationSearch: true, //查询
        btnRefrigerationExport: true,//导出excel
      }
    }

  }, mounted() {
    //按钮权限
    this.btnRight = this.$route.meta.buttons;
    //遍历属性赋值将true与false字符串转换成布尔型的值
    for (var key of Object.keys(this.btnRight)) {
      this.btnRight[key] = (this.btnRight[key] || this.btnRight[key] == "true") ? true : false;
    }
    this.onSubmit()
    var that = this
    window.onresize = function () {
      var search = document.getElementsByClassName("fileSearch")[0].offsetHeight
      var dom = document.getElementsByClassName("PageContent")[0].offsetHeight
      that.tableHeight = dom - search - 110
    }

  },
  //注销window.onresize事件
  destroyed() {
    window.onresize = null;
  },
  updated() {
    this.$nextTick(() => {
      var dom = document.getElementsByClassName("PageContent")[0].offsetHeight
      var search = document.getElementsByClassName("fileSearch")[0].offsetHeight
      this.tableHeight = dom - search - 110
    })
  },
  methods: {
    onSubmit(value) {
      this.loading = true
      if (value) {
        this.pager.currentPage = 1;
      }
      var postData = {
        "businessCode": this.ruleForm.businessCode,
        "deadName": this.ruleForm.deadName,
        "realityTimeStart": dataFormatetmd(new Date(this.ruleForm.realityTimeStart)),
        "realityTimeEnd": dataFormatetmd(new Date(this.ruleForm.realityTimeEnd)),
        "processStateCode": this.ruleForm.processStateCode,
        "equipmentTypeCode": this.ruleForm.equipmentTypeCode,
        "equipmentCode": this.ruleForm.equipmentCode,
        "pageSize": this.pager.pageSize,
        "currentPage": this.pager.currentPage,
        "exportExcelFlag": 0,            //0表示显示 1表示导出execl
        "orderField	": "",     //排序字段
        "orderType": ""        //排序顺序
      }
      //查询接口
      Type['loadColdStorage'](postData).then(response => {
        const {data} = response;
        if (!data) {
          this.loading = false;
          this.$message('数据读取失败')
          return
        }
        this.tableData = data.list
        this.pager = data.pager
        this.loading = false
        //   //数据读取成功
      }).catch(error => {
        this.$message(error)
        this.loading = false
        this.tableData = []
      })
    },
    // 初始页currentPage、初始每页数据数pagesize和数据data
    handleSizeChange: function (size) {
      this.pager.pageSize = size;
      this.onSubmit()
    },
    handleCurrentChange: function (currentPage) {
      this.pager.currentPage = currentPage;
      this.onSubmit()  //点击第几页
    },
    openExecl() {
      // window.location.href = "excel地址"
      var postData = {
        "businessCode": this.ruleForm.businessCode,
        "deadName": this.ruleForm.deadName,
        "appointmentTimeStart": dataFormatetmd(new Date(this.ruleForm.appointmentTimeStart)),
        "appointmentTimeEnd": dataFormatetmd(new Date(this.ruleForm.appointmentTimeEnd)),
        "pageSize": this.pager.pageSize,
        "currentPage": this.pager.currentPage,
        "exportExcelFlag": 1,            //0表示显示 1表示导出execl
        "orderField	": "",     //排序字段
        "orderType": ""        //排序顺序
      }
      download.exportExcel(Type["ColdStorageEXPEXC"], postData, "冷藏业务_" + download.getDateTime() + ".xlsx");

    },
  }
}
</script>

<style scoped>

</style>
